| Total Complexity | 2 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 7 | |||
| 8 | @QueryHandler(GetSchoolsQuery) |
||
| 9 | export class GetSchoolsQueryHandler { |
||
| 10 | constructor( |
||
| 11 | @Inject('ISchoolRepository') |
||
| 12 | private readonly schoolRepository: ISchoolRepository |
||
| 13 | ) {} |
||
| 14 | |||
| 15 | public async execute( |
||
| 16 | query: GetSchoolsQuery |
||
| 17 | ): Promise<Pagination<SchoolView>> { |
||
| 18 | const { page } = query; |
||
| 19 | const schoolViews: SchoolView[] = []; |
||
| 20 | const [ schools, total ] = await this.schoolRepository.findSchools(page); |
||
| 21 | |||
| 22 | for (const school of schools) { |
||
| 23 | schoolViews.push( |
||
| 24 | new SchoolView( |
||
| 25 | school.getId(), |
||
| 26 | school.getName(), |
||
| 27 | school.getReference(), |
||
| 28 | school.getAddress(), |
||
| 29 | school.getCity(), |
||
| 30 | school.getZipCode(), |
||
| 31 | school.getStatus(), |
||
| 32 | school.getType() |
||
| 33 | ) |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | return new Pagination<SchoolView>(schoolViews, total); |
||
| 38 | } |
||
| 40 |